import static org.junit.Assert.*;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;


public class ESundialMathTest {
	
	private ESundialMath test1;
	private ESundialMath test2;
	private ESundialMath test3;
	private double hypotenus;
	
	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception {
	}

	@Before
	public void setUp() throws Exception {
		double[] temp = {0.1, 1.1, 2.1};
		test1 = new ESundialMath(20, "testing",temp);
		test2 = new ESundialMath(25, "testing",temp);
		test3 = new ESundialMath(30, "testing",temp);
	}

	@After
	public void tearDown() throws Exception {
	}

	@Test
	public void test() {
		this.hypotenus = test1.CalculateEGnomon(test1.getlatitude());
		assertTrue(getOpp(this.hypotenus, test1.getlatitude()) == getOpp2(test1.getRadius(), test1.getlatitude()));

		this.hypotenus = test2.CalculateEGnomon(test2.getlatitude());
		assertTrue(getOpp(this.hypotenus, test2.getlatitude()) == getOpp2(test2.getRadius(), test2.getlatitude()));
		
		this.hypotenus = test3.CalculateEGnomon(test3.getlatitude());
		assertTrue(getOpp(this.hypotenus, test3.getlatitude()) == getOpp2(test3.getRadius(), test3.getlatitude()));
		
		//if negative number is send then CalcuateEGnomon returns 0
		assertTrue(test1.CalculateEGnomon(-10) == 0);
	}
	/**
	 * Use trig identities to find the opposite of an angle
	 * @param hypo
	 * @param lat
	 * @return
	 */
	private int getOpp(double hypo, double lat){
		return (int) (hypo * Math.sin(Math.toRadians(lat)));
	}
	/**
	 * Using trig identities to find the opposite an angle
	 * @param hypo
	 * @param lat
	 * @return
	 */
	private int getOpp2(double hypo, double lat){
		return (int) (hypo * Math.sin(Math.toRadians(2*lat)));
	}
}
